package servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cdj.User;

/**
 * Servlet implementation class HandleServlet
 */
@WebServlet("/HandleServlet")
public class HandleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HandleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	User u=new User();
	request.setCharacterEncoding("utf-8");
	String username = null,password = null,email = null,introduce=null;
	String[] favorites = null;
	try{
		username=request.getParameter("username");
		password=request.getParameter("password");
		favorites=request.getParameterValues("favorite");
		email=request.getParameter("email");
		introduce=request.getParameter("introduce");
	}catch(Exception ex)
	{
		ex.printStackTrace();
	}
	u.setEmail(email);
	u.setFavorite(favorites);
	u.setUsername(username);
	u.setPassword(password);
	u.setIntroduce(introduce);
	request.getSession().setAttribute("regUser", u);
	request.getRequestDispatcher("../user.jsp").forward(request,response);
	}
}